Hell you are welcome in this lecture.
We'll be creating the functionality for how our app using javascript.
So I've got my javascript file here or on the blank files.
Well this is where I'll will be adding the javascript.
Could they way I'm going to structure this lecture is to rewrite the code add it and then explain it
so that you don't have to waste time you watching me type and then explain it all right.
All right.
I've created two variables called variable number one variable number to this busy CLI it will generate
the number when the game stuff so variable one variable to well randomly generate numbers when the game
starts using the variables created in line 1 and 2 line 3 and 4 have added.
For example I am using what you have defined a variable you can just use it by the name so I'm using
variable 1 online 3 saying number 1 and I've set it with variables.
I defined a variable.
I didn't set the value.
So when you creating a variable you can set the values at the same time.
Or you can set it later.
So in this case I am setting the value later.
Which is in line 3 and 5 4 3.
I'm using the variable number 1 and I've set it took equal to the function Mat's the top floor must
flow from chambers's clearly is used to return the largest integer integers The number is used to return
the largest integer.
That is less than or equal to a given number.
So for example if I have caught a number forty five point ninety five the masto floor will return a
value of forty five.
Okay so it is used to return the largest integer on number.
That is less than or equal to a given number.
Right and if you notice I have also set records from shows that have to take in the parameter.
You can also pass in functions into other functions as barometers as well coming down here.
I have now passed in a lot of functions called maths dot Randall.
In fact that function.
What mascott random Does must run done.
Is used to a return random numbers between 0 which is inclusive and one which is exclusive right.
So do it.
That must that rundown will generate random number for our game.
And here times I've used the operator earthier times 10 so it would generate 10 random numbers at that
time and it would be incremental increase them by one each time.
Same here line for here.
I'm using the variable from line to same name setted to must top floor and past the admin must to a
random function again multiplied a run of say the random number she should generate is 10 but this should
increase as it is time by 1.
That's what I have done here line 3 and 4 and 5 here I am using the documentor get element back a day
and pass the variable number one.
So we send and get eliminated by the variable number one and dot in the CML was number one.
So this dot in a to a replaced.
In any email wait no one with this variable.
There's no one here.
If we go back to our t mail file does this is this.
No what is referring to is referring to d div.
Okay and then the db number two.
So that's what we mean here.
My number one number two.
So who's gonna grab that to what this code is saying is that good today hastier mail DB take all that
that is here mail Deve and inject.
This value is variable here which is just number one which is different.
It is variable so is gone on tick of an additive and inject the variable the random number generator.
Here is going to inject that in that Dave.
Okay similar thing on number 6.
It will go to the hastier mail to Cleveland Dave and inject this variable generated automatically from
line form.
That's what that means.
It means replace was step before with the value specify.
I've created another variable online line called variable answer.
This variable will provide the answers for the additions write some variable of coded answer and the
values number one plus number two so if you add the random number generator eg from 1 for a variable
number one agreeable number two and he to provide the answer.
I have added some more code here like 11 to 13 created a variable called check answer in line 11 so
it is variable we allow you to check for your answer was You have imported it in and have sent it to
you course to documents.
Query select query select or method basically is used to return the first element that matches is specified
x SS select all or select tors in the document.
So in this case it's referring to the inputs alright and by line 12 here a variable called value and
the answer is set it too close to check.
Answer done value.
So what these variable do it will take the value of the check answer variable and add it to whatever
value has been put into a well of only user types into the input for the addition it will add value
to the total value variable and displayed variable.
13 is like 13 is the button and attached to the button set it to a document but query select time is
in the query select a gain insight that the input and type is a button and the value is.
Check check.
The value is check is what will be displayed inside the button.
That is the text they'll be displayed.
I have had a good function here on line 14.
I have used the Boston variable that was created on line 13 so I've used a bottom variable there and
I'm at tast the On Click event to it and I've set it to a function so it clicked click basically event
is that when you click a button it triggers a function.
So this is a function.
I'm defining here.
Okay so the content between this function can you see the opening curly braces and the end here.
This is what happens when the button is clicked.
So basically what's in the value.
Okay.
Notice you got a variable there called value as well on line 12.
So what I'm saying here on line 15 is that the variable value equal to check answer dot value of the
variables will quote check answer that add value and dont introduce an if state if statement.
I used to determine conditions under which a code will execute.
So line 16 here is saying that if the value is strictly equal to a double double is equal.
If the value is equal to answer yes then you should see alert you to pop up an alert box and say you
are correct.
If the value is not equal to the answer.
For example if you type in one bloss one and he says two the alert will come up and say you are correct.
If the answer is wrong else there means that the answer is wrong then do.
Display the second message which is alert.
You are incorrect.
The answer was plus.
And then it will add the answer remember we created the variables can answer it all now.
And the correct answer after displaying the message you are incorrect.
So if stood bent I used to execute.
Could based on the conditions.
So the first condition is correct.
You get the first alert.
It does not correct you get the second look at as part of the function from line twenty two to twenty
eight.
We've got documents dot query select on methods whereby when the button is clicked is you have to impled
the tax and if whatever you put the value will be added then line 23 got documental.
Get elemen back Heidi to e all p carb the eidy from the div which is number one and then it will insert
to replace that using the.
Now don't hit him.
I'll replace that with the value that's been tightening.
You notice the code says blank.
So who has represented the value that will be typed in their line 24 document the LMM by this same thing
with no Deve.
Number two he tool.
Replace that and insert the code of value tag team twenty five line twenty five news in the variable
number 1 again.
Of course I am using that same function again.
These are the functions the variables now were defined earlier so I'm using that variable with a MUST
top floor past in the mizar Round on.
It would generate 10 random numbers and increase by 1 each time 20 seats line 26 same theme.
It will generate 10 random numbers and increase my one a time line.
27 is a document.
Get LMA it data to gently to pick the div number one DBD number two and replace it with the value of
the variable number one and a variable number two.
I am 30 is the answer.
So again I'm calling the variable there Ansal which is equal so number one.
Number two.
So basically what I've done is that within this function I have included more so the variables that
were defined earlier on the variables are defined early.
Also just incorporate them into the function so this function will be fired off when the button is clicked.
So let me say that and then we can test.
Our less test day app to make sure everything is working so one plus 7 are typing it.
Now click on check answer it told me are correct so this is where the function what sort of form Chad
has been wrapped around inside this checkbox here or right the button so he generate another number.
Type in 14 and told me you are correct.
So our or maths game is working correctly.
Thank you so much for watching.
Are there any parts of these projects you do not understand.
Please do let me know.
Be more than happy to help.
I have not included the code for this purpose because some want you to try and work things out.
But if you do have any issues please to let me know.
Thanks for watching.
All the best.
Bye for now.